_realname=yubico-c
_shortname=libyubikey
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.13
pkgrel=1
pkgdesc="Yubico YubiKey C library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://github.com/Yubico/yubico-c'
license=('BSD')
depends=(
  "${MINGW_PACKAGE_PREFIX}-curl"
  "${MINGW_PACKAGE_PREFIX}-libusb"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
validpgpkeys=('0A3B0262BCA1705307D5FF06BCA00FD4B2168C0A') # Klas Lindfors <klas@yubico.com>
source=("https://developers.yubico.com/${_realname}/Releases/${_shortname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('04edd0eb09cb665a05d808c58e1985f25bb7c5254d2849f36a0658ffc51c3401'
            'SKIP')

prepare() {
  cd ${srcdir}/${_shortname}-${pkgver}

  autoreconf -fvi
}

build() {
  cd "${srcdir}"/${_shortname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  ../${_shortname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}

  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}

  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_shortname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
